package com.eascs.ant.data.service;

import java.util.LinkedList;
import java.util.List;

import javax.inject.Inject;

import org.bson.Document;
import org.springframework.stereotype.Service;

import com.eascs.ant.common.service.BaseSevice;
import com.eascs.ant.data.dao.MongoDbDao;
import com.eascs.ant.data.entity.news.NewsResult;
import com.eascs.ant.data.platform.Platform;

@Service
public class NewsService extends BaseSevice{

	@Inject
	MongoDbDao mongoDao;
	
	public List<NewsResult> queryLatestNews(){
		//查询各新闻平台最新5条新闻
		//List<String> platforms = Platform.getAllPlatform();
		List<NewsResult> newsResults = new LinkedList<NewsResult>();
		String[] descendFields = new String[]{"publishTime"};
		List<Document> tempList = mongoDao.getData(Platform.NC_INFO.getPlatform(),20 , descendFields);
		for(Document doc : tempList){
			NewsResult nr = new NewsResult();
			nr.setTitle(doc.getString("title"))
			  .setSourceUrl(doc.getString("url"))
			  .setPlatform(doc.getString("platform"))
			  .setContent(doc.containsKey("digest")?doc.getString("digest"):doc.getString("content"))
			  .setPublicateTime(doc.containsKey("time")?doc.getDate("time"):doc.getDate("publishTime"));
			 
			newsResults.add(nr);
		}
		return newsResults;
	}

	
}
